import { nanoid } from 'nanoid'
export default {
    namespaced: true, // 开启命名空间
    state: {
        persons: []
    },
    actions: {
        addPerson(context, value) {
            console.log('actions中的addPerson被调用', context, value);
            if (!value.trim()) {
                alert('姓名不能为空')
                return
            }
            const person = { id: nanoid(), name: value }
            context.commit('ADD_PERSON', person)
        }
    },
    mutations: {
        ADD_PERSON(state, value) {
            state.persons.unshift(value)
        }
    },
    getters: {
        bigSum(state) {
            return state.sum * 10
        }
    }
}